package main

import (
	"fmt"
)

func main() {
	fmt.Println(hasPathSum(&TreeNode{
		Val: 3,
		Left: &TreeNode{
			Val: 20,
		},
		Right: &TreeNode{
			Val: 20,
			Left: &TreeNode{
				Val: 15,
			},
			Right: &TreeNode{
				Val: 7,
			},
		},
	}, 23))
}

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

func hasPathSum(root *TreeNode, targetSum int) bool {
	if root == nil {
		return false
	}
	var targetSub int
	if targetSub = targetSum - root.Val; targetSub == 0 {
		if root.Left == nil && root.Right == nil {
			return true
		}
	}
	return hasPathSum(root.Left, targetSub) || hasPathSum(root.Right, targetSub)
}
